package org.jaaksi.kottlindemo.home

import androidx.annotation.IdRes
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.asSharedFlow
import kotlinx.coroutines.launch
import org.jaaksi.kottlindemo.dao.model.db.Note

class HomeViewModel : ViewModel() {
    private val _changeTabFlow = MutableSharedFlow<Int>()
    // 对我暴露的是ReadonlySharedFlow和changeTab方法，外界不能直接调用changeTabFlow进行emit
    val changeTabFlow = _changeTabFlow.asSharedFlow()


    val dataChangedFlow = MutableSharedFlow<List<Note>>(replay = 1)

    fun changeTab(@IdRes id:Int){
        viewModelScope.launch {
            _changeTabFlow.emit(id)
        }
    }
}